﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace 第六次作业
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        string fp1, fp2;
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                
                openFileDialog.RestoreDirectory = false;                    //若为false，则打开对话框后为上次的目录。若为true，则为初始目录
                
                if (openFileDialog.ShowDialog() == DialogResult.OK)
                {
                    textBox1.Clear();
                    fp1 = Path.GetFullPath(openFileDialog.FileName);//将选中的文件的路径传递给TextBox “FilePath”
                    using (StreamReader sr = new StreamReader(fp1))
                    {
                        string line;
                        // 从文件读取并显示行，直到文件的末尾 
                        while ((line = sr.ReadLine()) != null)
                        {
                            textBox1.Text += line;
                        }
                    }
                }
            }
            catch { }
        }
        private void button2_Click(object sender, EventArgs e)
        {
            try
            {
                openFileDialog.RestoreDirectory = false;    //若为false，则打开对话框后为上次的目录。若为true，则为初始目录
                if (openFileDialog.ShowDialog() == DialogResult.OK)
                {
                    textBox2.Clear();
                    fp2 = Path.GetFullPath(openFileDialog.FileName);//将选中的文件的路径传递给TextBox “FilePath”
                    using (StreamReader sr = new StreamReader(fp2))
                    {
                        string line;
                        // 从文件读取直到文件的末尾 
                        while ((line = sr.ReadLine()) != null)
                        {
                            textBox2.Text += line;
                        }
                    }
                }
            }
            catch { }
        }
        private void button3_Click(object sender, EventArgs e)
        {
            try
            {
                using (StreamWriter sw = new StreamWriter(".\\data\\合并后的文本.txt"))
                {
                    string[] content = new string[] { textBox1.Text, textBox2.Text };
                    foreach(string s in content)
                    {
                        sw.WriteLine(s);
                    }
                }
                MessageBox.Show("合并成功！请在data目录中查看！");
           
            }
            catch { }
        }


    }
}
